<nz-card>
  <nz-descriptions
    nzTitle="基本信息"
    nzBordered
    nzSize="small"
    [nzColumn]="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }"
  >
    <nz-descriptions-item nzTitle="单号">
      {{ detailsData.allocationNumber || '-' }}
      <i
        *ngIf="detailsData.allocationNumber"
        nz-icon
        nzType="copy"
        nzTheme="outline"
        nz-tooltip
        nzTooltipTitle="点击复制"
        (click)="coprText(detailsData.allocationNumber)"
      ></i>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="新建人">{{ detailsData.founder || '-' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="新建时间">{{ detailsData.createTime || '-' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="状态">
      <span [ngStyle]="{'color': detailsData.state | storageAllocationState: 'color'}">
        {{ detailsData.state | storageAllocationState: 'label' }}
      </span>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="出库仓库">
      {{ filterText(storeOptions, detailsData.deliveryWhId, 'id') }}
    </nz-descriptions-item>

    <nz-descriptions-item nzTitle="调出时间">{{ detailsData.deliveryTime || '-' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="调拨类型">
      {{ filterText(allocationTypeOptions, detailsData.type, 'content') }}
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="入库仓库">
      {{ filterText(storeOptions, detailsData.warehousingWhId, 'id') }}
    </nz-descriptions-item>

    <nz-descriptions-item nzTitle="调入时间">{{ detailsData.warehousingTime || '-' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="备注" nzSpan="4">{{ detailsData.remark || '-' }}</nz-descriptions-item>
  </nz-descriptions>
</nz-card>

<nz-card class="m-t-4">
  <p class="detail-title">调拨明细</p>

  <div class="table-wrap">
    <nz-table
      #mxTable
      nzBordered
      nzSize="small"
      [nzShowPagination]="false"
      [nzFrontPagination]="false"
      [nzData]="detailedTableData"
      (nzCurrentPageDataChange)="onCurrentPageDataChange($event)">
      <thead>
        <tr>
          <th
            rowspan="2"
            nzWidth="50px"
            nzAlign="center"
            [(nzChecked)]="checked"
            [nzIndeterminate]="indeterminate"
            (nzCheckedChange)="onAllChecked($event)"
          ></th>
          <th nzAlign="center" rowspan="2" nzWidth="70px">序号</th>
          <th nzAlign="center" colspan="5">商品信息</th>
          <th nzAlign="center" colspan="2">调出信息</th>
          <th nzAlign="center" rowspan="2">调入信息</th>
          <th nzAlign="center" rowspan="2">操作</th>
        </tr>
        <tr>
          <th nzAlign="center">商品状态</th>
          <th nzAlign="center">商品名称</th>
          <th nzAlign="center">商品编号</th>
          <th nzAlign="center">商品69码</th>
          <th nzAlign="center">SN管控</th>

          <th nzAlign="center">预计出库数量</th>
          <th nzAlign="center">调出信息</th>
        </tr>
      </thead>
      <tbody>
        <tr
          *ngFor="let data of mxTable.data; let index = index;"
          [ngClass]="{'tr-bg-red': data?.lineState === 1}">
          <td
            [nzDisabled]="data.lineState === 1"
            [nzChecked]="setOfCheckedId.has(data.id)"
            (nzCheckedChange)="onItemChecked(data.id, $event)"
          ></td>
          <!-- 序号 -->
          <td nzAlign="center">{{ index + 1 }}</td>
          <!-- 商品状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.whGoodsState === 0 ? '#999999' : '#67C23A'}">
              {{ data.whGoodsState === 0 ? '禁用' : (data.whGoodsState === 1 ? '启用' : '-') }}
            </span>
          </td>
          <!-- 商品名称 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.whGoodsState === 0 ? '#999999' : ''}">
              {{ data?.whGoodsName || '-' }}
            </span>
          </td>
          <!-- 商品编号 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.whGoodsState === 0 ? '#999999' : ''}">
              {{ data?.whGoodsCode || '-' }}
            </span>
          </td>
          <!-- 商品69码 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.whGoodsState === 0 ? '#999999' : ''}">
              {{ data?.whGoodsTwoCode || '-' }}
            </span>
          </td>
          <!-- SN管控 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.type === 1 ? '#67C23A' : ''}">
              {{ data.type === 1 ? '是' : '-' }}
            </span>
          </td>
          
          <!-- * 预计出库数量 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data?.deliveryNumber !== data.actualDeliveryNumber ? '#FF9900' : ''}">
              {{ data?.deliveryNumber || '0' }}
            </span>
          </td>
          <!-- 调出信息 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': setTextColor(data)}">
              {{ data.deliveryQuality === 0 ? '不良品' : (data.deliveryQuality === 1 ? '良品' : '-') }}
              {{ data.actualDeliveryNumber }}
            </span>
          </td>

          <!-- 调入信息 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': setTextColor(data)}">
              {{ handleTransferText(data) }}
            </span>
          </td>
          <!-- 操作 -->
          <td nzAlign="center">
            <button
              nz-button
              nzType="link"
              nzSize="small"
              (click)="showDetailModal(data)"
            >详情</button>
          </td>
        </tr>

        <tr *ngIf="detailedTableData?.length" style="background: #fafafa; font-weight: 600;">
          <td nzAlign="center" colSpan="7">合计</td>
          <!-- 预计出库数 -->
          <td nzAlign="center">{{ calcSumTotal('deliveryNumber') }}</td>
          <!-- 实际出库数 | 调出信息 -->
          <td nzAlign="center">{{ calcSumTotal('actualDeliveryNumber') }}</td>
          <td nzAlign="center">-</td>
          <td nzAlign="center">-</td>
        </tr>
      </tbody>
    </nz-table>
  </div>
</nz-card>

<nz-card class="m-t-4">
  <div nz-row nzJustify="center">
    <button
      *ngIf="permission.userPermission.has('storageCt:allocation:zf') && [2, 3, 4, 5].includes(detailsData.state)"
      nz-button
      nzType="primary"
      class="m-r-10"
      (click)="showTovoidModal()"
    >作废</button>

    <button
      nz-button
      nzType="default"
      (click)="pageBack()"
    >返回</button>
  </div>
</nz-card>

<!-- S 作废 Modal -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isZfVisible"
  [nzTitle]="'提示'"
  (nzOnCancel)="isZfVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <p class="zf-tips">该操作不可逆，作废后该行彻底失效</p>
      
      <nz-form-item>
        <nz-form-label nzRequired>备注</nz-form-label>
        <nz-form-control>
          <nz-textarea-count [nzMaxCharacterCount]="100">
            <textarea
              rows="4"
              nz-input
              maxlength="100"
              placeholder="请输入备注、必填"
              [(ngModel)]="toVoidRemark"
            ></textarea>
          </nz-textarea-count>
        </nz-form-control>
      </nz-form-item>
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="default" (click)="isZfVisible = false">取消</button>
        <button nz-button nzType="primary" [nzLoading]="submitZfLoading" (click)="submitToVoidData()">确定作废</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- S 作废 Modal -->

<!-- S SN信息 Modal -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [nzWidth]="1100"
  [(nzVisible)]="isSninfoVisible"
  [nzTitle]="'SN信息'"
  (nzOnCancel)="isSninfoVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <div class="p-t-10">
        <nz-table
          #sninfoTable
          nzSize="small"
          nzBordered
          [nzShowPagination]="false"
          [nzData]="snModalTable">
          <thead>
            <tr>
              <th nzAlign="center" nzWidth="100px">序号</th>
              <th nzAlign="center">SN码</th>
              <th nzAlign="center">出库库位</th>
              <th nzAlign="center">调出品质</th>
              <th nzAlign="center">入库库位</th>
              <th nzAlign="center">调入品质</th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let data of sninfoTable.data; let index = index;">
              <!-- 序号 -->
              <td nzAlign="center">{{ index + 1 }}</td>
              <!-- SN码 -->
              <td nzAlign="center">{{ data.code || '-' }}</td>
              <!-- 出库库位 -->
              <td nzAlign="center">
                {{ filterText(locationOptions, data.deliveryLibraryId, 'id') }}
              </td>
              <!-- 调出品质 -->
              <td nzAlign="center">
                {{ data.deliveryQuality === 0 ? '不良品' : (data.deliveryQuality === 1 ? '良品' : '-') }}
              </td>
              <!-- 入库库位 -->
              <td nzAlign="center">
                {{ filterText(locationOptions, data.warehousingLibraryId, 'id') }}
              </td>
              <!-- 调入品质 -->
              <td nzAlign="center">
                {{ data.warehousingQuality === 0 ? '不良品' : (data.warehousingQuality === 1 ? '良品' : '-') }}
              </td>
            </tr>
          </tbody>
        </nz-table>
      </div>
    </div>
  </div>
</nz-modal>
<!-- S SN信息 Modal -->

<!-- S 多库位 Modal -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isDkwVisible"
  [nzTitle]="'多库位'"
  (nzOnCancel)="isDkwVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <div>
        <b class="dkw-ptile">调出信息</b>
        <nz-table
          #dkwTableOne
          nzSize="small"
          nzBordered
          [nzShowPagination]="false"
          [nzData]="locationOneTable">
          <thead>
            <tr>
              <th nzAlign="center" nzWidth="100px">序号</th>
              <th nzAlign="center">调出库位</th>
              <th nzAlign="center">调出数量</th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let data of dkwTableOne.data; let index = index;">
              <!-- 序号 -->
              <td nzAlign="center">{{ index + 1 }}</td>
              <!-- 调出库位 -->
              <td nzAlign="center">
                {{ filterText(locationOptions, data.deliveryLibraryId, 'id') }}
              </td>
              <!-- 调出数量 -->
              <td nzAlign="center">
                {{ data.num || '-' }}
              </td>
            </tr>
          </tbody>
        </nz-table>
      </div>

      <div class="p-t-15">
        <b class="dkw-ptile">调入信息</b>
        <nz-table
          #dkwTableTwo
          nzSize="small"
          nzBordered
          [nzShowPagination]="false"
          [nzData]="locationTwoTable">
          <thead>
            <tr>
              <th nzAlign="center" nzWidth="100px">序号</th>
              <th nzAlign="center">调入库位</th>
              <th nzAlign="center">调入数量</th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let data of dkwTableTwo.data; let index = index;">
              <!-- 序号 -->
              <td nzAlign="center">{{ index + 1 }}</td>
              <!-- 调入库位 -->
              <td nzAlign="center">
                {{ filterText(locationOptions, data.warehousingLibraryId, 'id') }}
              </td>
              <!-- 调入数量 -->
              <td nzAlign="center">
                {{ data.num || '-' }}
              </td>
            </tr>
          </tbody>
        </nz-table>
      </div>
    </div>
  </div>
</nz-modal>
<!-- S 多库位 Modal -->